package com.imu.purse.admin.controller.base;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import com.imu.common.annotation.SysLog;
import com.imu.common.utils.R;
import com.imu.common.validator.ValidatorUtils;
import com.imu.common.validator.group.AddGroup;
import com.imu.common.validator.group.UpdateGroup;
import com.imu.purse.modules.base.entity.UserLoginEntity;
import com.imu.purse.modules.base.service.UserLoginService;
import com.xiaoleilu.hutool.bean.BeanUtil;

/**
 * 用户登录记录
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2017-11-08 10:31:21
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
@RestController
@RequestMapping("base/userlogin")
public class UserLoginController extends com.imu.purse.modules.sys.controller.AbstractController
{
	/****
	 * 查询用户登录记录
	 * @param params
 	 * @date 2017-11-08 10:31:21
	 * @return
	 */
	@SysLog("查询用户登录记录")
	@GetMapping("/list")
	@RequiresPermissions("base:userlogin:list")
	public R list(@RequestParam Map<String, Object> params)
	{
		R r = R.ok();
		if(CollectionUtils.isEmpty(params)) return r;
		
		UserLoginEntity dto = BeanUtil.mapToBean(params, UserLoginEntity.class, true);
		List<UserLoginEntity> dtos = service.queryList(dto);
		if(CollectionUtils.isEmpty(dtos)) return r;
		
		return r.put("page", new PageInfo<UserLoginEntity>(dtos));
	}
	
	/****
	 * 根据ID查询用户登录记录
	 * @param sulId
 	 * @date 2017-11-08 10:31:21
	 * @return
	 */
	@SysLog("根据ID查询用户登录记录")
	@GetMapping("/info/{sulId}")
	@RequiresPermissions("base:userlogin:info")
	public R info(@PathVariable("sulId") Long sulId)
	{
		return R.ok().put("dto", service.findById(sulId));
	}
	
	/****
	 * 新增用户登录记录
	 * @param dto
 	 * @date 2017-11-08 10:31:21
	 * @return
	 */
	@SysLog("新增用户登录记录")
	@PostMapping("/save")
	@RequiresPermissions("base:userlogin:save")
	public R save(@RequestBody UserLoginEntity dto)
	{
		ValidatorUtils.validateEntity(dto, AddGroup.class);
		service.save(dto);
		return R.ok();
	}
	
	/****
	 * 修改用户登录记录
	 * @param dto
 	 * @date 2017-11-08 10:31:21
	 * @return
	 */
	@SysLog("修改用户登录记录")
	@PostMapping("/update")
	@RequiresPermissions("base:userlogin:update")
	public R update(@RequestBody UserLoginEntity dto)
	{
		ValidatorUtils.validateEntity(dto, UpdateGroup.class);
		service.update(dto);
		return R.ok();
	}
	
	/****
	 * 删除用户登录记录
	 * @param ids
 	 * @date 2017-11-08 10:31:21
	 * @return
	 */
	@SysLog("删除用户登录记录")
	@PutMapping("/delete")
	@RequiresPermissions("base:userlogin:delete")
	public R delete(@RequestBody String[] ids)
	{
		service.delete(ids);
		return R.ok();
	}
	
	@Autowired
	private UserLoginService service;
}
